package com.ffapp.demo.bean;


import com.ffapp.demo.basis.Constants;

import java.util.ArrayList;

import my.FileUtils;

public class UserSensitiveWordsBean extends BasisBean {
    public static final String FILE_CACHE = Constants.DIR_FILECACHE
            + "sensivivewords.data";

    private ArrayList<String> list = new ArrayList<>();

    public ArrayList<String> getList() {
        return list;
    }

    public void setList(ArrayList<String> list) {
        this.list = list;
    }

    public static UserSensitiveWordsBean getFromCache() {
        return  (UserSensitiveWordsBean) FileUtils.readObject(FILE_CACHE);
    }

    public void save() {
        FileUtils.cacheObject(FILE_CACHE, this);
    }

    private static void delete() {
        FileUtils.cacheObject(FILE_CACHE, null);
    }

    public boolean isContentSensitive(String content){
        if(list == null|| list.size() == 0)return false;
        for(String word:list){
            if(content.contains(word))return true;
        }
        return false;
    }
    public String getSenstivieWords(String content){
        StringBuilder builder = new StringBuilder();
        if(list == null|| list.size() == 0)return "";
        for(String word:list){
            if(content.contains(word)){
                builder.append(word).append(",");
            }
        }
        if(builder.length() > 0)
            builder.deleteCharAt(builder.length()-1);

        return builder.toString();
    }

}
